<template>
  <div id="audit">
    <el-row>
      <el-col :span="4" :offset="20">
        <el-select v-model="search.status" @change="searchByCondition" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
      </el-col>
    </el-row>
    <el-row style="margin-top: 10px;">
      <el-table
            :data="registerList"
            style="width: 100%">
            <el-table-column
              prop="storeName"
              label="商铺名称"
              width="180">
            </el-table-column>
            <el-table-column
              prop="linkman"
              label="联系人姓名"
              width="180">
            </el-table-column>
            <el-table-column
              prop="phone"
              label="联系人电话">
            </el-table-column>
            <el-table-column
              prop="statusName"
              label="审核状态">
            </el-table-column>
            <el-table-column
              prop="check"
              label="操作">
              <template slot-scope="scope">
                <el-button v-if="scope.row.status==0" @click="audit(scope.row)" type="text" size="medium">审 核</el-button>
              </template>
            </el-table-column>
          </el-table>
    </el-row>


    <el-dialog
      title="审核"
      :visible.sync="showWindows"
      width="60%"
      :before-close="handleClose">
      <el-descriptions title="用户信息">
        <el-descriptions-item label="商铺名称">{{register.storeName}}</el-descriptions-item>
        <el-descriptions-item label="地址">{{register.address}}</el-descriptions-item>
        <el-descriptions-item label="联系电话">{{register.phone}}</el-descriptions-item>
        <el-descriptions-item label="联系人">{{register.linkman}}</el-descriptions-item>
        <el-descriptions-item label="商铺创建人">{{register.createUser}}</el-descriptions-item>
        <el-descriptions-item label="商铺创建时间">{{register.createDate}}</el-descriptions-item>
        <el-descriptions-item label="许可证">
          <el-image
                style="width: 100px; height: 100px"
                :src="register.permit"
                :fit="fit"></el-image>
        </el-descriptions-item><br>
        <el-descriptions-item label="营业执照">
          <el-image
                style="width: 100px; height: 100px"
                :src="register.license"
                :fit="fit"></el-image>
        </el-descriptions-item><br>
      </el-descriptions>
      <el-radio-group v-if="register.statusName == '待审核'" v-model="status" style="margin-bottom: 20px;">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="2">驳回</el-radio>
      </el-radio-group>
      <el-input v-if="status==2" v-model="rejectReason" placeholder="驳回原因"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="register.statusName == '待审核'" type="primary" @click="doAudit()">提交</el-button>
        <el-button v-if="register.statusName == '待审核'" @click="showWindows = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'Audit',
    data() {
      return{
        registerList:[],
        search:{
        },
        register : {
        },
        status:1,
        rejectReason: "",
        showWindows: false,
        options: [{
                  value: '0',
                  label: '待审核'
                }, {
                  value: '1',
                  label: '已通过'
                }, {
                  value: '2',
                  label: '未通过'
                }, {
                  value: '',
                  label: '全部'
                }]

      }
    },
    created() {
      this.list()
    },
    methods: {
      list(){
        this.$http.post("/storeRegister/search",this.search).then(resp=>{
          this.registerList = resp.data.data.list
        })
      },
      audit(data) {
        this.register = data;
        this.showWindows = true;
      },
      doAudit() {
        this.$http.post("/storeRegister/updateStatus",
        {
          accountId: this.register.accountId,
          newStatus: this.status,
          rejectReason: this.rejectReason
        }).then(resp => {
          alert(resp.data.message);
          this.list();
          this.showWindows = false;
        })
      },
      searchByCondition(){

        this.$http.post("/storeRegister/search",this.search).then(resp=>{
          this.registerList = resp.data.data.list
        })
      }
    },

  }
</script>

<style scoped>

</style>
